/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on 21/05/2012, 19:21:39
 */
package views;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import models.Funcionario;

/**
 *
 * @author 40800431
 */
public class MainWindow extends javax.swing.JFrame {

    private final Funcionario systemUser;
 
    /** Creates new form MainFrame */
    public MainWindow(Funcionario user) {
        this.systemUser = user;
        
        initComponents();
        
        MainScreen ms = new MainScreen(this);
        this.setContentPane(ms);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainMenu = new javax.swing.JMenuBar();
        menuItemPrincipal = new javax.swing.JMenu();
        subMenuNovo = new javax.swing.JMenu();
        subItemNovoCliente = new javax.swing.JMenuItem();
        subItemNovoProjeto = new javax.swing.JMenuItem();
        subItemNovoTarefa = new javax.swing.JMenuItem();
        subItemNovoFuncionario = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        subMenuItemLancarHoras = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        subMenuItemSair = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Gerenciador de Projetos");
        setMaximizedBounds(getMaximizedBounds());
        setName("mainFrame"); // NOI18N

        menuItemPrincipal.setText("Principal");

        subMenuNovo.setText("Novo");

        subItemNovoCliente.setText("Cliente");
        subItemNovoCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subItemNovoClienteActionPerformed(evt);
            }
        });
        subMenuNovo.add(subItemNovoCliente);

        subItemNovoProjeto.setText("Projeto");
        subItemNovoProjeto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subItemNovoProjetoActionPerformed(evt);
            }
        });
        subMenuNovo.add(subItemNovoProjeto);

        subItemNovoTarefa.setText("Tarefa");
        subItemNovoTarefa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subItemNovoTarefaActionPerformed(evt);
            }
        });
        subMenuNovo.add(subItemNovoTarefa);

        subItemNovoFuncionario.setText("Funcionário");
        subMenuNovo.add(subItemNovoFuncionario);

        jMenuItem1.setText("Cronograma");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        subMenuNovo.add(jMenuItem1);

        menuItemPrincipal.add(subMenuNovo);

        subMenuItemLancarHoras.setText("Lançar horas...");
        subMenuItemLancarHoras.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subMenuItemLancarHorasActionPerformed(evt);
            }
        });
        menuItemPrincipal.add(subMenuItemLancarHoras);
        menuItemPrincipal.add(jSeparator1);

        subMenuItemSair.setText("Sair");
        subMenuItemSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subMenuItemSairActionPerformed(evt);
            }
        });
        menuItemPrincipal.add(subMenuItemSair);

        mainMenu.add(menuItemPrincipal);

        setJMenuBar(mainMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 750, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 529, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void subMenuItemLancarHorasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subMenuItemLancarHorasActionPerformed
        swapPanels(new FormHoras(this));
    }//GEN-LAST:event_subMenuItemLancarHorasActionPerformed

    private void subMenuItemSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subMenuItemSairActionPerformed
        if(JOptionPane.showConfirmDialog(this, "Tem certeza que deseja sair?", "Gerenciador de Projetos", JOptionPane.OK_CANCEL_OPTION) == 0){
            this.dispose();
        }
    }//GEN-LAST:event_subMenuItemSairActionPerformed

    private void subItemNovoClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subItemNovoClienteActionPerformed
        swapPanels(new FormCliente(this));
    }//GEN-LAST:event_subItemNovoClienteActionPerformed

    private void subItemNovoProjetoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subItemNovoProjetoActionPerformed
        FormProjeto swapPanel = new FormProjeto(this);
        this.getContentPane().removeAll();
        this.setContentPane(swapPanel);
        this.validate();
    }//GEN-LAST:event_subItemNovoProjetoActionPerformed

    private void subItemNovoTarefaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subItemNovoTarefaActionPerformed
        swapPanels(new FormTarefa(this));
    }//GEN-LAST:event_subItemNovoTarefaActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        swapPanels(new FormCronograma(this));
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               
            }
        });
    }
    
    public void returnToHome(){
        swapPanels(new MainScreen(this));
    }
    
    private void swapPanels(JPanel newFrame){
        int frameWidth = this.getWidth();
        int frameHeight = this.getHeight();
        
        int panelWidth = newFrame.getWidth();
        int panelHeight = newFrame.getHeight();
        
        int xPos = (frameWidth - panelWidth) / 2;
        int yPos = (frameHeight - panelWidth) / 2;
        
        newFrame.setLocation(xPos, yPos);
        
        this.getContentPane().removeAll();
        this.setContentPane(newFrame);
        this.validate();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenuBar mainMenu;
    private javax.swing.JMenu menuItemPrincipal;
    private javax.swing.JMenuItem subItemNovoCliente;
    private javax.swing.JMenuItem subItemNovoFuncionario;
    private javax.swing.JMenuItem subItemNovoProjeto;
    private javax.swing.JMenuItem subItemNovoTarefa;
    private javax.swing.JMenuItem subMenuItemLancarHoras;
    private javax.swing.JMenuItem subMenuItemSair;
    private javax.swing.JMenu subMenuNovo;
    // End of variables declaration//GEN-END:variables
}
